﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AdrHook;
using System.Runtime.InteropServices;




namespace keyhook
{

    

    public partial class mainFrm : Form
    {
        [DllImport("user32.dll")]
        private static extern bool SetForegroundWindow(IntPtr hWnd);
        [DllImport("user32.dll")]
        private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);


        public mainFrm()
        {
            InitializeComponent();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                HookManager.KeyPress += HookManager_KeyPress;
            }
            else
            {
                HookManager.KeyPress -= HookManager_KeyPress;
            }

        }


        private void HookManager_KeyPress(object sender, KeyPressEventArgs e)
        {
         

            if (e.KeyChar.ToString() == "a") {

                //this.WindowState = FormWindowState.Maximized;


                SetForegroundWindow(this.Handle);
                
                this.Focus();
            }

            message.AppendText(string.Format("KeyPress - {0}\n", e.KeyChar));
            message.ScrollToCaret();
        }

        private void mainFrm_Load(object sender, EventArgs e)
        {

        }


    }
}
